package com.ruoyi.cmdb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cmdb.domain.Resolution;
import com.ruoyi.cmdb.service.IResolutionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 解析Controller
 * 
 * @author ruoyi
 * @date 2023-01-27
 */
@RestController
@RequestMapping("/cmdb/resolution")
public class ResolutionController extends BaseController
{
    @Autowired
    private IResolutionService resolutionService;

    /**
     * 查询解析列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:resolution:list')")
    @GetMapping("/list")
    public TableDataInfo list(Resolution resolution)
    {
        startPage();
        List<Resolution> list = resolutionService.selectResolutionList(resolution);
        return getDataTable(list);
    }

    /**
     * 导出解析列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:resolution:export')")
    @Log(title = "解析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Resolution resolution)
    {
        List<Resolution> list = resolutionService.selectResolutionList(resolution);
        ExcelUtil<Resolution> util = new ExcelUtil<Resolution>(Resolution.class);
        util.exportExcel(response, list, "解析数据");
    }

    /**
     * 获取解析详细信息
     */
    @PreAuthorize("@ss.hasPermi('cmdb:resolution:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(resolutionService.selectResolutionById(id));
    }

    /**
     * 新增解析
     */
    @PreAuthorize("@ss.hasPermi('cmdb:resolution:add')")
    @Log(title = "解析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Resolution resolution)
    {
        return toAjax(resolutionService.insertResolution(resolution));
    }

    /**
     * 修改解析
     */
    @PreAuthorize("@ss.hasPermi('cmdb:resolution:edit')")
    @Log(title = "解析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Resolution resolution)
    {
        return toAjax(resolutionService.updateResolution(resolution));
    }

    /**
     * 删除解析
     */
    @PreAuthorize("@ss.hasPermi('cmdb:resolution:remove')")
    @Log(title = "解析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(resolutionService.deleteResolutionByIds(ids));
    }
}
